//
//  AppDelegate.m
//  hnGovernment
//
//  Created by 安仔 on 17/2/24.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "AppDelegate.h"

#import "XJNavigationController.h"
#import "XJTabBarController.h"
#import "IQKeyboardManager.h"
#import "SVProgressHUD.h"
#import "DDbaseNetWork+Login.h"
#import "DDAPPUpdateHelper.h"
#import "DDNetworkSwitchHelper.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // 界面的初始化
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    XJTabBarController *xjTabBarController = [[XJTabBarController alloc] init];
    self.window.rootViewController = xjTabBarController;
    [self.window makeKeyAndVisible];
    // 键盘库的初始化
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    // hud库的初始化
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    // 网络库的初始化
    [DDNetWorkManager configBaseNetWorkNeedLogParams:NO defaultRequestSerializer:DDRequestSerializerJSON errorHandle:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (error.code == -1001) {
                [SVProgressHUD showErrorWithStatus:NSLocalString(@"网络超时,请重试")];
            }else if(error.code == -1009) {
                [SVProgressHUD showErrorWithStatus:NSLocalString(@"没有网络，请检查网络设置")];
            }else {
                [SVProgressHUD showErrorWithStatus:NSLocalString(@"服务器错误,稍后重试")];
            }
        });
    }];
    // 升级功能的初始化
    [[DDAPPUpdateHelper shareInstance]monitor];
    // ip切换功能的初始化
    NSMutableArray *serviceArray = [NSMutableArray array];
    DDServiceModel *item1  = [[DDServiceModel alloc]init];
    item1.name = @"开发环境 http://120.26.168.214";
    item1.ip = @"http://120.26.168.214";
    [serviceArray addObject:item1];
    DDServiceModel *item2  = [[DDServiceModel alloc]init];
    item2.name = @"河南联调环境 http://42.236.64.41";
    item2.ip = @"http://42.236.64.41";
    [serviceArray addObject:item2];
    DDServiceModel *item3  = [[DDServiceModel alloc]init];
    item3.name = @"河南演示环境 http://42.236.65.201";
    item3.ip = @"http://42.236.65.201";
    [serviceArray addObject:item3];
    [[DDNetworkSwitchHelper shateInstance]initServiceArray:serviceArray defaultService:item1];
    return YES;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
